package online.flowerinsnow.minecraft.bukkit.floweress.util

import online.flowerinsnow.minecraft.bukkit.floweress.message.MessageConfig
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player

class CommandUtils {
    companion object {
        @JvmStatic
        fun checkPermission(sender : CommandSender, permission : String) : Boolean {
            return if (sender.hasPermission(permission)) {
                sender.sendMessage(MessageConfig.NOPERMISSION.getMessage()
                        .replace("%(PERMISSION)", permission))
                true
            } else false
        }

        @JvmStatic
        fun checkConsole(sender: CommandSender) : Boolean {
            return if (sender is Player) {
                sender.sendMessage(MessageConfig.CONSOLE.getMessage())
                true
            } else false
        }

        @JvmStatic
        fun checkPermissionAndConsole(sender : CommandSender, permission: String) : Boolean {
            return checkPermission(sender, permission) || checkConsole(sender)
        }
    }
}